package CAD;

import j3d.J3D;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;

import features.Feature;

import visualCAD.RemoveFeatureView;


public class RemoveFeature extends RemoveFeatureView implements ActionListener {

	JComboBox featureComboBox;
	private J3D j3d = null;
	public RemoveFeature(J3D j3d) {
		this.j3d=j3d;
		String arg[]=new String[MainFrame.features.size()];
		int i=0;
		for(Feature feature: MainFrame.features){
			arg[i]=feature.toString();
			i++;
		}
		featureComboBox=new JComboBox(arg);
		featurePanel.add(featureComboBox, BorderLayout.CENTER);
		addActions();
		pack();
		setVisible(true);
		
	}
	
	private void addActions() {
		okButton.addActionListener(this);
		cancelButton.addActionListener(this);
	}

	public void actionPerformed(ActionEvent evt) {
		
		Object source = evt.getSource();
		if(source.equals(okButton)){
			MainFrame.features.remove(featureComboBox.getSelectedIndex());//remove a feature selecionada do array de nomes de features
		    MainFrame.block.block = MainFrame.block.makeRawBlock(); 
			this.j3d.addSolidWithFeatures(MainFrame.features,MainFrame.block.block); //passa lista de features e o bloco cru
			MainFrame.refreshJTree();
			dispose();
		}
		if(source.equals(cancelButton)){
			dispose();
		}
	}

}
